﻿@model TestOnlineProject.Models.Entities.Subject
@{
    ViewBag.Title = "Details";
}
@{
    if (!String.IsNullOrEmpty(ViewBag.Msg))
    {
    <script>        alert("@ViewBag.Msg")</script>
    }
}
<script>
    $(document).ready(function () {
        $("#deactivate").click(function () {
            var con = confirm("Are you sure you want to deactivate this subject?");
            if (con == true) {
                $.ajax({
                    url: "@Url.Content("~/Subject/Deactivate")?ids=@Model.SubjectId" + "-",
                    type: 'GET',
                    success: function (data) {
                        if (data != null) {
                            alert(data);
                            window.location = "@Url.Content("~/Subject/Details")?id=@Model.SubjectId";
                        }
                    }
                })
            }
        }); 
        
        $("#activate").click(function () {
            var con = confirm("Are you sure you want to activate this subject?");
            if (con == true) {
                $.ajax({
                    url: "@Url.Content("~/Subject/Activate")?ids=@Model.SubjectId" + "-",
                    type: 'GET',
                    success: function (data) {
                        if (data != null) {
                            alert(data);
                            window.location = "@Url.Content("~/Subject/Details")?id=@Model.SubjectId";
                        }
                    }
                })
            }
        });

        $("#delete").click(function () {
            var con = confirm("Are you sure you want to delete this subject?");
            if (con == true) {
                $.ajax({
                    url: "@Url.Content("~/Subject/Delete")?ids=@Model.SubjectId" + "-",
                    type: 'GET',
                    success: function (data) {
                        if (data != null) {
                            alert(data);
                            window.location = "@Url.Content("~/Subject/Index")";
                        }
                    }
                })
            }
        });
    })
</script>
<div class="site_map">
    @Html.ActionLink("Home", "Index", "Home") / @Html.ActionLink("Subjects", "Index", "Subject", new { }, null)
    / <span style="word-wrap: break-word">@Model.Code</span></div>
<br />
<div class="main_nav">
    <span><a href="@Url.Content("~/Subject/Index")">
        <img src="@Url.Content("~/Images/back button.png")" /></a> </span><span style="float: right">
            @if (HttpContext.Current.User.IsInRole("1"))
            {
                @Html.ActionLink("Participants", "Index", "Participant", new { subjectId = @Model.SubjectId }, new { }) <span>|</span>
            }
            @Html.ActionLink("Sections", "Index", "Section", new { subjectId = @Model.SubjectId }, new { })
            |
            @Html.ActionLink("Questions", "Index", "Question", new { subjectId = @Model.SubjectId }, new { })
            |
            @Html.ActionLink("Tests", "Index", "Test", new { subjectId = @Model.SubjectId }, new { })
            |
            @Html.ActionLink("Discussions", "Index", "Discussion", new { subjectId = @Model.SubjectId }, new { })
        </span>
</div>
<br />
@{
    if (!Model.IsActivated)
    {
    <div class="alert alert-error">
        <span>Deactivated.</span>
    </div>
    }
}
<table class="table table-bordered" style="table-layout: fixed; margin: 0px">
    <tr>
        <td style="width: 150px; text-align: right">
            <span>Code</span>
        </td>
        <td>
            <span style="word-wrap: break-word">@Html.DisplayFor(model => Model.Code)</span>
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
            <span>Name</span>
        </td>
        <td>
            <span style="word-wrap: break-word">@Html.DisplayFor(model => Model.Name)</span>
        </td>
    </tr>
    @{
        if (HttpContext.Current.User.IsInRole("1"))
        {
        <tr>
            <td style="text-align: right">
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id = @Model.SubjectId }) <span>|</span>
                @if
                (Model.IsActivated)
                { <a href="#" id="deactivate">Deactivate</a> }
                else
                { <a href="#" id="activate">Activate</a> }
                <span>|</span>
                @Html.ActionLink("Delete", "Delete")
            </td>
        </tr>
        }
    }
</table>
